/*
 *
 * Copyright (c) 2001-2018 泛微软件.
 * 泛微协同商务系统,版权所有.
 * 
 */
package com.engine.demo.cmd;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import com.cloudstore.eccom.base.WeaDataOption;
import com.cloudstore.eccom.constant.WeaInputType;
import com.cloudstore.eccom.constant.WeaViewAttr;
import com.cloudstore.eccom.core.WeaDataChange;
import com.cloudstore.eccom.pc.form.WeaForm;
import com.cloudstore.eccom.pc.form.WeaFormGroup;
import com.cloudstore.eccom.result.WeaResultMsg;
import weaver.conn.RecordSet;
import weaver.general.Util;
import weaver.hrm.User;
import weaver.systeminfo.SystemEnv;
import com.engine.common.biz.AbstractCommonCommand;
import com.engine.common.entity.BizLogContext;
import com.engine.core.interceptor.CommandContext;
import com.engine.demo.dao.DemoDao;


/**
 *
 * 用户自定义设置 CMD AndyZhang 2018-6-22
 * @version 1.0
 */
public class DoFormDemoCmd extends AbstractCommonCommand<Map<String, Object>>{
	/**
     * 日志信息
     */
	public BizLogContext getLogContext() {
		return null;
	}
	
	/**
     * 构造方法
     * @param params
     * @param user
     */
	public DoFormDemoCmd(Map<String, Object> params, User user){
        this.user = user;
        this.params = params;
    }
	
	/**
     * Command类方法实现
     * @param commandContext
     * @return
     */
	public Map<String, Object> execute(CommandContext commandContext) {
		
		WeaResultMsg result=new WeaResultMsg(false);
		
		HashMap<String,String> valueMap = new HashMap<String,String>();
		
		int id = Util.getIntValue(Util.null2String(params.get("id")), 0);

		if(id!=0){
			DemoDao dao = new DemoDao();
	        String sql = dao.getOne();
	        RecordSet rs = new RecordSet();
	        rs.executeQuery(sql, id);
	        valueMap = WeaDataChange.getRecordToMap(rs);
		}
        
		WeaForm form =new WeaForm();
		form.setValueMap(valueMap);
		WeaFormGroup group=form.addGroup("demo","1");

		group.addItem(WeaInputType.INPUT, "测试", "EM_PASSWORD").setViewAttr(WeaViewAttr.READONLY).setHelpfulTip("test");
		group.addItem(WeaInputType.INPUTNUMBER, "测试", "EM_URL_OPEN").setViewAttr(WeaViewAttr.REQUIRED);
		

        //驱动级别列表
        List<WeaDataOption>  driverLevelList = new ArrayList<WeaDataOption>();
        driverLevelList.add(new WeaDataOption("1",SystemEnv.getHtmlLabelName(129719, user.getLanguage()), false));
        driverLevelList.add(new WeaDataOption("2",SystemEnv.getHtmlLabelName(129720, user.getLanguage()), false));
        //驱动级别
  
        group.addItem(WeaInputType.SELECT, "测试", "ACCESSTOKEN").setOptions(driverLevelList).setViewAttr(WeaViewAttr.REQUIRED);

        form.refreshValuesByMap();
        result.putAll(form.makeDataResult());

        return result.getResultMapAll();
	}
	
	
}
